package com.htl.实用类;

public class StringBuffer__test {
    public static void main(String[] args) {
        StringBuffer stringBuffer = new StringBuffer();
        System.out.println(stringBuffer);
        System.out.println(stringBuffer.length());  // 0
        stringBuffer = new StringBuffer("Hello World");
        System.out.println(stringBuffer);   // Hello World
        //下标为2的字符
        System.out.println(stringBuffer.charAt(2)); // l
        //追加内容
        stringBuffer.append("Java");
        System.out.println(stringBuffer);   // Hello WorldJava
        //删除指定区间的内容
        stringBuffer.delete(3, 6);
        System.out.println(stringBuffer);   // HelWorldJava
        //删除指定下标的字符
        stringBuffer.deleteCharAt(3);
        System.out.println(stringBuffer); // HelorldJava
        //替换指定区间的内容
        stringBuffer.replace(2, 3, "StringBuffer");
        System.out.println(stringBuffer); // HeStringBufferorldJava
        //截取
        String str = stringBuffer.substring(3);
        System.out.println(str); // tringBufferorldJava
        //截取区间
        String substring = stringBuffer.substring(3, 6);
        System.out.println(substring);  // tri
        //在指定下标插入字符
        stringBuffer.insert(6, "six");
        System.out.println(stringBuffer);   // HeStrisixngBufferorldJava
        //获取某个字符的下标
        int r = stringBuffer.indexOf("r", 6);
        System.out.println(r);  // 16
        //字符反转
        stringBuffer.reverse();
        System.out.println(stringBuffer);   // avaJdlroreffuBgnxisirtSeH
    }
}

